package com.zyb.patient.adapter;

import java.sql.Date;
import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zyb.patient.R;
import com.zyb.patient.dto.BaseDto;
import com.zyb.patient.dto.CourseDto;
import com.zyb.patient.util.Options;
import com.zyb.patient.util.StringUtil;

public class AboutMeClassAdapter extends BaseAdapter {

	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	private Context context;
	private List<CourseDto> list;
	private LayoutInflater inflater;

	public AboutMeClassAdapter(Context context, List<CourseDto> list) {
		this.context = context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
		this.imageLoader = ImageLoader.getInstance();
		if (!imageLoader.isInited()) {
			Options.initImageLoaderConfiguration(ImageLoader.getInstance(),
					context);
		}
		this.options = Options.getListOptions();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public BaseDto getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
//		ViewHolder holder = null;
//		if (convertView == null) {
//			convertView = inflater.inflate(
//					R.layout.activity_about_me_class_list_item1, null);
//			holder = new ViewHolder();
//
//			holder.selectedImg = (ImageView) convertView
//					.findViewById(R.id.img1);
//			holder.courseImg = (ImageView) convertView.findViewById(R.id.img2);
//			holder.categoryTv = (TextView) convertView.findViewById(R.id.tv1);
//			holder.titleTv = (TextView) convertView.findViewById(R.id.tv2);
//			holder.contentTv = (TextView) convertView.findViewById(R.id.tv3);
//
//			convertView.setTag(holder);
//		} else {
//			holder = (ViewHolder) convertView.getTag();
//		}
		CourseDto cDto = list.get(position);
		if ("0".equals(cDto.isShowTop)) {
			convertView = inflater.inflate(
				R.layout.activity_about_me_class_list_item1, null);
			TextView categoryTv = (TextView) convertView.findViewById(R.id.tv1);
			if (cDto.state.equals("0")) {
				categoryTv.setText("当前课程");
			} else if (cDto.state.equals("1")) {
				categoryTv.setText("已完成");
			} else if (cDto.state.equals("2")) {
				categoryTv.setText("已取消");
			}
		} else {
			convertView =inflater.inflate(
					R.layout.activity_about_me_class_list_item2, null);
			ImageView selectedImg = (ImageView) convertView
					.findViewById(R.id.img1);
			ImageView courseImg = (ImageView) convertView.findViewById(R.id.img2);
			TextView titleTv = (TextView) convertView.findViewById(R.id.tv2);
			TextView contentTv = (TextView) convertView.findViewById(R.id.tv3);
			
			if (!TextUtils.isEmpty(cDto.name))
				titleTv.setText(cDto.name);

			if (!TextUtils.isEmpty(cDto.content))
				contentTv.setText(cDto.content);

			if (!TextUtils.isEmpty(cDto.flag))
				selectedImg
						.setVisibility(cDto.flag.equals("0") ? View.VISIBLE
								: View.GONE);

			if (!TextUtils.isEmpty(cDto.url))
				imageLoader.displayImage(cDto.url, courseImg, options);
		}

		return convertView;
	}

//	static class ViewHolder {
//		ImageView selectedImg;
//		ImageView courseImg;
//		TextView titleTv;
//		TextView contentTv;
//		TextView categoryTv;
//
//	}

}
